/*
 * @Author: your name
 * @Date: 2020-10-16 10:15:44
 * @LastEditTime: 2021-11-17 10:14:22
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: /gatt-react/src/index/apis/Login/index.ts
 */
import request from '@/common/utils/request'
import { instanceProps } from '@/common/utils/request'

import { getParentUrl } from '@/common/utils'

// const isMock = process.env.APP_ENVO === 'dev'
const basePath = process.env.APP_ENVO === 'dev' ? './' : './'

export async function checkLoginTokenFn(params:any) {
  // 区分lab和非lab服务环境
  const parentUrl = getParentUrl()
  const url = parentUrl || `${process.env.APP_LOGIN_URL}`
  const path = url.includes('lab') ? 'sso.lab' : 'sso'
  const origin = url.includes('lab') ? 'app.lab.clickpaas.com' : 'app.clickpaas.com'
  return request({
    url: `//${path}.clickpaas.com/api/sso/login/checkStatus?origin=${origin}`,
    method: 'get',
    model: null,
    params
  } as instanceProps)
}

export async function getUserInfoByToken(params:Object) {
  return request({
    url: `${process.env.APP_BASE_API}${basePath}/query/userInfo`,
    method: 'get',
    model: null,
    params,
    ContentType: 'x-www-form-urlencoded',
    isPassTips: true // 拦截器里不对错误进行拦截提示
  } as instanceProps)
}
